package com.maochang.service.impl;


import com.maochang.bean.TAccount;
import com.maochang.dao.AccountDao;
import com.maochang.service.AccountMoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountMoneyServiceImpl implements AccountMoneyService {

    @Autowired
    public AccountDao accountDao;

    /**
     * 正常的业务操作
     * @param tAccount1
     * @param tAccount2
     */
    @Override
    public void accountMoney1(TAccount tAccount1,TAccount tAccount2) {
        //张三
        boolean b1 = accountDao.updateAccount1(tAccount1);
        //李四
        boolean b2 = accountDao.updateAccount2(tAccount2);
    }

    /**
     * 错误的业务操作
     * @param tAccount1
     * @param tAccount2
     */
    @Override
    //@Transactional
    public void accountMoney2(TAccount tAccount1, TAccount tAccount2) {
        //try {
            //第一步:开启事务

            //第二步:进行业务操作

                //张三少200
                boolean a = accountDao.updateAccount1(tAccount1);

                //算数异常
                int i=10/0;

                //李四多200
                boolean b = accountDao.updateAccount2(tAccount2);
                System.out.println(a+"---------"+b);

            //第三步:没发生异常,提交事务
        //} catch (Exception e) {

            //第四步:出现异常,事务回滚
            //e.printStackTrace();
        //}
    }
}
